﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SortingNullsLastWithLinq
{
	public class HockeyTeam
	{
		public string TeamName { get; set; }
		public int? Championships { get; set; }
		public override string ToString()
		{
			string output = TeamName;
			if(Championships.HasValue) output = output + " (" + Championships.Value + ")";
			return output;
		}

		public static List<HockeyTeam> Create()
		{
			List<HockeyTeam> localTeams = new List<HockeyTeam>{
				new HockeyTeam{TeamName = "Montreal Canadiens", Championships = 24},
				new HockeyTeam{TeamName = "Toronto Maple Leafs", Championships = 13},
				new HockeyTeam{TeamName = "Ottawa Senators"},
				new HockeyTeam{TeamName = "Buffalo Sabres"},
				new HockeyTeam{TeamName = "Boston Bruins", Championships = 6},
				new HockeyTeam{TeamName = "Detroit Red Wings", Championships = 11},
				new HockeyTeam{TeamName = "Florida Panthers"}
			};

			return localTeams;
		}
	}

	class Program
	{
		static void Main(string[] args)
		{
			List<HockeyTeam> localTeams = HockeyTeam.Create();

			IEnumerable<HockeyTeam> sorted =
				localTeams.OrderByDescending(x => x.Championships.HasValue)
				.ThenByDescending(x => x.Championships)
				.ThenBy(x => x.TeamName);

			foreach(var team in sorted)
				Console.WriteLine(team);

			Console.ReadLine();
		}
	}
}
